﻿namespace Sidvall.Business
{
    public sealed class BusinessSettingsManager : System.IDisposable
    {
        #region Public Members

        public void Dispose()
        {
            if (this.Provider != null)
            {
                this.Provider.BusinessSettings.Import(this.BusinessSettings);
                this.Provider = null;
            }
        }

        #endregion
        #region Private Members

        private IBusinessSettingsProvider Provider { get; set; }
        private BusinessSettings BusinessSettings { get; set; }

        #endregion
        #region Constructors

        public BusinessSettingsManager(IBusinessSettingsProvider provider)
            : this(provider, BusinessSettings.CreateSettingsNone())
        {
        }
        public BusinessSettingsManager(IBusinessSettingsProvider provider, BusinessEvents enabledEvents)
            : this(provider, BusinessSettings.CreateSettings(enabledEvents))
        {
        }
        public BusinessSettingsManager(IBusinessSettingsProvider provider, BusinessSettings businessSettings)
        {
            this.Provider = provider;
            if (this.Provider != null)
            {
                this.BusinessSettings = this.Provider.BusinessSettings.Copy();
                this.Provider.BusinessSettings.Import(businessSettings);
            }
        }

        #endregion
    }
}
